<template>
    <div class="header">
        <span class="cityName">{{ store.cityName }}</span>
        <input type="text" v-model="city" class="citys" @keyup.enter="onEnter" />
        <select name="" id="Draw" v-model="store.drawType">
            <option value="line">线条</option>
            <option value="polygon">多边形</option>
            <option value="circle">圆形</option>
            <option value="FreeLine">自由线</option>
            <option value="clear">清除画布</option>
        </select>
        <select name="" id="addIcon" v-model="store.addIcon" :disabled="store.zoom < 15">
            <option value="gas_station">加油站</option>
            <option value="charging_station">充电站</option>
            <option value="parking_lot">停车场</option>
            <option value="clear">清除画布</option>
        </select>
    </div>
</template>

<script setup>
import axios from 'axios';
import { ref } from 'vue';
import { useStore } from '@/stores/index.js';
const store = useStore();
store.axiosData();
const city = ref('');
const data = ref();
async function onEnter() {
    // 根据城市名称获取城市的中心经纬度
    const res = await axios.get(
        `https://restapi.amap.com/v3/geocode/geo?address=${city.value}&key=981114a7f1d2dbdc051e2236248e7dab`
    );
    data.value = res.data.geocodes[0];
    store.cityAdcode = data.value.adcode;
    store.center = data.value.location.split(',').map(Number);
    city.value = '';
}
</script>

<style lang="scss">
.header {
    display: flex;
    align-items: center;
    gap: 50px;
    min-width: 1000px;
    height: 100px;
    padding: 0 100px;
    background-color: blue;
    .cityName {
        width: 100px;
        height: 50px;
        font-size: 20px;
        color: white;
        line-height: 50px;
    }
    .cityAdcode {
        width: 120px;
        height: 50px;
        font-size: 18px;
        color: #fff;
        line-height: 50px;
    }
    .citys {
        width: 150px;
        height: 30px;
        border: none;
        padding-left: 10px;
        border-radius: 5px;
    }
    select {
        width: 150px;
        height: 30px;
        border: none;
        padding-left: 10px;
        border-radius: 5px;
    }
}
</style>
